package com.shanzmoo.merchant.manage.api.web.merchant;

import cn.hutool.http.useragent.UserAgentUtil;
import com.shanzmoo.base.bean.PageRespBase;
import com.shanzmoo.base.bean.SHttpResponse;
import com.shanzmoo.base.util.JYFException;
import com.shanzmoo.db.module.merchant.domain.dto.*;
import com.shanzmoo.db.module.merchant.domain.query.*;
import com.shanzmoo.db.module.merchant.domain.vo.*;
import com.shanzmoo.db.module.merchant.domain.vo.base.MerchantBaseInfoVo;
import com.shanzmoo.merchant.manage.api.manager.merchant.MerchantInfoManager;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @author 作者：zfj
 * @version 创建时间：2021年3月28日,0028
 * @classDesc 类描述
 */
@Slf4j
@Api(tags = "商户入驻")
@RestController
@RequestMapping("/merchantInfo")
@RequiredArgsConstructor
public class MerchantInfoController {

    // 入驻商户处理信息
    private final MerchantInfoManager merchantInfoManager;

    /**
     * 查询入驻商户信息
     *
     * @param query 入驻商户查询条件信息
     * @return
     */
    @ApiOperation(value = "查询入驻商户明细信息")
    @PostMapping("/selectMerchantInfo")
    public SHttpResponse<MerchantInfoDetailVo> selectMerchantInfo(@RequestBody MerchantInfoQuery query) {
        return merchantInfoManager.selectMerchantInfo(query);
    }

    /**
     * 保存/修改门店信息
     *
     * @return
     */
    @ApiOperation(value = "保存/修改门店信息")
    @PostMapping("/saveMerchantShop")
    public SHttpResponse<Boolean> saveMerchantShopEntity(@RequestBody MerchantShopVo merchantShop) {
        try {
            return merchantInfoManager.saveMerchantShopEntity(merchantShop);
        } catch (JYFException e){
            log.error("保存/修改门店信息异常，异常信息为：{}", e);
            return SHttpResponse.fail(100004, e.getMessage());
        } catch (Exception e){
            log.error("保存/修改门店信息异常，异常信息为：{}", e);
            return SHttpResponse.fail(100003, "更新门店信息失败");
        }
    }

    /**
     * 分页查询门店信息
     *
     * @return
     */
    @ApiOperation(value = "分页查询门店信息")
    @PostMapping("/selectMerchantShop")
    public SHttpResponse<PageRespBase<MerchantShopVo>> selectMerchantShop(@RequestBody MerchantShopQuery query) {
        return merchantInfoManager.selectMerchantShop(query);
    }

    /**
     * 查询门店详情信息
     *
     * @return
     */
    @ApiOperation(value = "查询门店详情信息")
    @PostMapping("/selectMerchantShopDetail")
    public SHttpResponse<MerchantShopVo> selectMerchantShopDetail(@RequestParam(value = "id") Integer id) {
        return merchantInfoManager.selectMerchantShopDetail(id);
    }


    /**
     * 保存/修改商户台卡信息
     *
     * @return
     */
    @ApiOperation(value = "保存/修改商户台卡信息")
    @PostMapping("/saveMerchantTerminal")
    public SHttpResponse<Boolean> saveMerchantTerminal(@RequestBody MerchantTerminalVo merchantTerminal) {
        try {
            return merchantInfoManager.saveMerchantTerminal(merchantTerminal);
        } catch (JYFException e){
            log.error("更新台卡信息异常，异常信息为：{}", e);
            return SHttpResponse.fail(100004, e.getMessage());
        } catch (Exception e){
            log.error("更新台卡信息异常，异常信息为：{}", e);
            return SHttpResponse.fail(100003, "更新台卡信息失败");
        }
    }

    /**
     * 开通或关闭商户台卡信息
     *
     * @return
     */
    @ApiOperation(value = "开通或关闭商户台卡信息")
    @PostMapping("/updateMerchantTerminal")
    public SHttpResponse<Boolean> updateMerchantTerminal(@RequestBody MerchantTerminalVo merchantTerminal) {
        try {
            return merchantInfoManager.updateMerchantTerminal(merchantTerminal);
        } catch (Exception e){
            log.error("开通或关闭商户台卡信息，异常信息为：{}", e);
            return SHttpResponse.fail(100003, "更新台卡信息失败");
        }
    }

    /**
     * 分页查询门店信息
     *
     * @return
     */
    @ApiOperation(value = "分页查询商户台卡信息")
    @PostMapping("/selectMerchantTerminal")
    public SHttpResponse<PageRespBase<MerchantTerminalVo>> selectMerchantTerminal(@RequestBody MerchantTerminalQuery query) {
        return merchantInfoManager.selectMerchantTerminal(query);
    }

    /**
     * 查询商户台卡详情信息
     *
     * @return
     */
    @ApiOperation(value = "查询商户台卡详情信息")
    @PostMapping("/selectMerchantTerminalDetail")
    public SHttpResponse<MerchantTerminalVo> selectMerchantTerminalDetail(@RequestParam(value = "id") Integer id) {
        return merchantInfoManager.selectMerchantTerminalDetail(id);
    }

}
